<?php
/**
 * CopyRight © 2014
 *
  -------------------------------------------------------------
 * File:     RequestUtil.php
 * Name:     RequestUtil
 * Version:  1.0
 * Date: 2014-08-05
 * Directory: include/util/RequestUtil.php
 * Author:   ZhangXiLian
 * Purpose: Request读取类
  -------------------------------------------------------------
 */
class RequestUtil {
	/** 获取GET参数
	 * @author ZhangXiLian */
	public static function getQuery($para_name) {
		if (! $_GET [$para_name]) {
			return null;
		}
		return self::GetStr( $_GET [$para_name] );
	}
	/** 获取POST参数
	 * @author ZhangXiLian */
	public static function getPost($para_name) {
		if (! $_POST [$para_name]) {
			return null;
		}
		return self::GetStr( $_POST [$para_name] );
	}
	/**
	 * 获取REQUEST参数
	 * @author ZhangXiLian
	 */
	public static function getReq($para_name) {
		if (! $_REQUEST [$para_name]) {
			return null;
		}
		return self::GetStr( $_REQUEST [$para_name] );
	}
	/**
	 * 过滤字符所有非法字符
	 * @author ZhangXiLian
	 */
	public static function GetStr($str) {
		if ($str != null && trim ( $str ) != "") {
			return self::SqlEncode ( self::ClearBR ( self::ClearHtml ( $str ) ) );
		}
		return "";
	}
	/**
	 * 过滤Html
	 * @author ZhangXiLian
	 */
	public static function ClearHtml($strHtml) {
		if ($strHtml != "") {
			// $strHtml = preg_replace("/<[^>]+>/", "", $strHtml);
			$strHtml = preg_replace ( "/<\/?[^>]*>/", "", $strHtml );
		}
		return $strHtml;
	}
	/**
	 * 过滤换行符
	 * @author ZhangXiLian
	 */
	public static function ClearBR($strHtml) {
		if ($strHtml != "") {
			$strHtml = preg_replace ( "/(\r)/", "", $strHtml );
			$strHtml = preg_replace ( "/(\n)/", "", $strHtml );
		}
		return $strHtml;
	}
	/**
	 * 过滤'字符 "字符,防止SQL注入
	 * @author ZhangXiLian
	 */
	public static function SqlEncode($str) {
		if ($str == null) {
			return "";
		} else {
			return str_replace("\"", "“",str_replace("'", "''", $str));
		}		
	}
}//End Class

?>